package com.zryc.shop.oms.controller;

import com.zryc.shop.base.Result;
import com.zryc.shop.oms.entity.OrderReturnApply;
import com.zryc.shop.oms.service.IOrderReturnApplyService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.*;
import org.springframework.stereotype.Controller;

import java.util.Arrays;
import java.util.Date;

/**
 * <p>
 * 订单退货申请 前端控制器
 * </p>
 *
 * @author zhaozhao
 * @since 2024-01-18
 */
@RestController
@Api(tags = "退货申请管理")
@RequestMapping("/oms/returnApply")
public class OrderReturnApplyController {

    @Autowired
    private IOrderReturnApplyService orderReturnApplyService;

    @GetMapping("/list")
    @ApiOperation("分页查询列表")
    public Result list(@RequestParam(defaultValue = "1") @ApiParam(value = "页码", required = true) Integer pageNum,
                       @RequestParam(defaultValue = "10") @ApiParam(value = "每页显示条数", required = true) Integer pageSize,
                       @RequestParam(required = false) @ApiParam("服务单号ID") Integer id,
                       @RequestParam(required = false) @ApiParam("退货申请状态") Integer status,
                       @RequestParam(required = false) @DateTimeFormat(pattern = "yyyy-MM-dd") @ApiParam("申请时间") Date createTime,
                       @RequestParam(required = false) @ApiParam("处理人员") String handleMan,
                       @RequestParam(required = false) @DateTimeFormat(pattern = "yyyy-MM-dd") @ApiParam("处理日期") Date handleTime){
        return Result.ok(orderReturnApplyService.list(pageNum, pageSize, id, status, createTime, handleMan, handleTime));//注意隔天的时间处理
    }

    @GetMapping("/{id}")
    @ApiOperation("查询详情")
    public Result info(@PathVariable Long id){
        return Result.ok(orderReturnApplyService.getById(id));
    }

    @PostMapping("/update/status/{id}")
    @ApiOperation("修改状态")
    public Result updateStatus(@PathVariable Long id, @RequestBody OrderReturnApply returnApply){
        return Result.ok(orderReturnApplyService.updateStatus(id,returnApply));
    }

    @PostMapping("/delete")
    @ApiOperation("删除")
    public Result delete(@RequestParam String ids){
        String[] idList=ids.split(",");
        return  Result.ok(orderReturnApplyService.removeBatchByIds(Arrays.asList(idList)));
    }


}
